<?php

/**
 * @author FDG367
 * @time 2017-11-29
 */

namespace common\models;

use Yii;
use yii\db\ActiveRecord;

class LogWebException extends ActiveRecord{

    public static function tableName(){
        return '{{%log_web_exception}}';
    }

    public function rules(){
        return [
            [['create_time','type','code','message','data'],'safe']
        ];
    }

	/**
	 * @param bool $insert
	 * @return bool|void
	 */
	public function beforeSave($insert){
		$this->create_time = date('Y-m-d H:i:s');
		return parent::beforeSave($insert);
	}

	/**
	 * @param $e  错误日志信息
	 * @param array $data
	 * @param int $type
	 * @return bool
	 */
	public  function saveLog($code,$message='',$data=[],$type=1){
		$this->type 	= $type;
		$this->code 	= $code;
		$this->message 	= $message;
		$this->data 	= $data ?json_encode($data):'';
		if(!$this->save()){
			return false;
		}

		return true;

	}
}